package com.atguigu.demo.customer.service.impl;

import com.atguigu.demo.customer.bean.Customer;
import com.atguigu.demo.customer.mapper.CustomerMapper;
import com.atguigu.demo.customer.service.CustomerService;
import com.baomidou.dynamic.datasource.annotation.DS;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

@Service  //标识该类 是服务层组件 默认单态 整个服务只有一个对象 // 容器启动的是会创建该对象
@DS("mysql0519")
public class CustomerServiceImpl extends ServiceImpl<CustomerMapper,Customer> implements CustomerService {

    @Autowired
    CustomerMapper customerMapper;

    @Override
    //@Transactional  // 可以控制事务  必须是同源数据库
    public void saveCustomer(Customer customer) {
        System.out.println("服务层保存："+customer);
        customerMapper.insertCustomer(customer);//2021
        customerMapper.insert(customer); //0519


    }

    @Override
    public Customer getCustomerById(Long id) {

        Customer customer = customerMapper.selectCustomerById(id);
        return customer;
    }
}
